Skip to content

Add --order to python -m nameparser - #983

Merged
derek73 merged 2 commits into
masterfrom
feat/cli-name-order
Oct 31, 2026
Merged

derek73 merged 2 commits into
masterfrom
feat/cli-name-order

Conversation

@derek73

@derek73 derek73 commented Oct 31, 2026 •

Copy link
Copy Markdown
Owner

Summary

python -m nameparser read every name in the default order. It now takes --order, one of given-first, family-first or family-first-given-last (the three Policy.name_order values, spelled as the vocabulary [rules] tables spell them):

$ python -m nameparser --order family-first --json "Kovács János Péter"
{"title": "", "given": "János", "middle": "Péter", "family": "Kovács", "suffix": "", "nickname": "", "maiden": ""}

Without the flag the same name gives given Kovács, family Péter.

  • With --locale, the order is written into the pack's own PolicyPatch, so it replaces any order the pack sets (none ships one today) without parser_for's two-pack conflict warning, and the parser is built once, so parser_for re-emits a construction warning (the --locale ja segmenterless one) from main's frame, once.
  • Limits, stated in the help, docs/usage.rst and the release log: a name wholly in Han, Hangul or kana keeps its script's order (Policy.script_orders), and a family comma fixes the order.
  • A bad value exits 2 listing the choices (argparse choices).
  • Tests join the existing tests/v2/test_cli.py, in process: each order; a pack's vocabulary (es, Lic) and policy (cs, two family names) kept under --order; a stand-in pack's order replaced; a Han name keeping its order; exactly one warning, attributed to __main__.py; the CLI's _ORDERS held equal to _locale._ORDERS, of which it is a copy because __main__ imports only the public package.

No parser behavior changes, so no rules or snapshot moves.

Test plan

  • uv run pytest (34,146 passed)
  • uv run mypy
  • uv run ruff check

🤖 Generated with Claude Code

The command line helper read every name in the default order. --order
takes given-first, family-first or family-first-given-last, the three
Policy.name_order values, and is applied after --locale so the explicit
flag wins over an order a pack sets. Adds tests/v2/test_main.py, the
CLI's first test module.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@derek73 derek73 self-assigned this Oct 31, 2026
@derek73 derek73 added this to the 3.0 milestone Oct 31, 2026
Review of the first commit: dataclasses.replace on the built Parser ran
Parser.__post_init__ a second time, so --locale ja --order printed the
segmenterless warning twice, the copy attributed to dataclasses.py. The
order now goes into the pack's own PolicyPatch (or a pack of its own),
so parser_for builds once and re-emits from main's frame, and a pack's
order is replaced without a two-pack conflict warning.

The tests move into the existing tests/v2/test_cli.py, dropping two
that repeated it, and gain rows for a pack's policy kept (cs), a pack's
order replaced (a stand-in pack, since none ships one), a Han name
keeping its script's order, one warning, and _ORDERS held to _locale's.
The help, usage.rst and release log state the script and comma limits,
and the bullet links the PR.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@derek73
derek73 merged commit b577e9a into master Oct 31, 2026
13 checks passed
@derek73
derek73 deleted the feat/cli-name-order branch October 31, 2026 19:43
derek73 added a commit that referenced this pull request Oct 31, 2026
Review of #984: the fallback caught every ImportError, so an installed
but broken namedivider (numpy failing to import) was reported as not
installed, its cause dropped; and the parser's warning it fell back to
offered remedies that are code a command line cannot pass, and showed
nothing under PYTHONWARNINGS=ignore. The CLI now tests for the package
with find_spec, lets any load failure propagate, and in its absence
prints a note naming the install and filters the parser's warning by
message.

Tests: the segmenter survives every --order and an uppercase JA; the
missing extra notes once and warns nothing; a broken install fails with
its own ImportError or OSError; the zh check records calls rather than
raising, since a broad catch would have swallowed the AssertionError.
#983's warns-once test goes: the CLI no longer reaches that warning.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
derek73 added a commit that referenced this pull request Oct 31, 2026
…locale ja (#984)

* Attach the installed Japanese segmenter under python -m nameparser --locale ja

The CLI took the ja pack but had no way to attach a segmenter, so
--locale ja divided nothing and warned. It now calls
locales.ja_segmenter() for the ja pack and passes it to parser_for,
falling back to the segmenterless parser, and its warning, when the
extra is not installed. parser_for(locales.JA) stays explicit:
decisions/D1 records the library-wide form as declined, since the same
code would parse differently with and without the extra.

The #983 warning test assumed --locale ja always warns; it now makes
the extra missing, so it holds in the ja-extra job too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Link #984 from its release-log bullet

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Fall back only on a missing namedivider, with a note in the CLI's terms

Review of #984: the fallback caught every ImportError, so an installed
but broken namedivider (numpy failing to import) was reported as not
installed, its cause dropped; and the parser's warning it fell back to
offered remedies that are code a command line cannot pass, and showed
nothing under PYTHONWARNINGS=ignore. The CLI now tests for the package
with find_spec, lets any load failure propagate, and in its absence
prints a note naming the install and filters the parser's warning by
message.

Tests: the segmenter survives every --order and an uppercase JA; the
missing extra notes once and warns nothing; a broken install fails with
its own ImportError or OSError; the zh check records calls rather than
raising, since a broad catch would have swallowed the AssertionError.
#983's warns-once test goes: the CLI no longer reaches that warning.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Correct D1's pickle reason and cite #984; note the CLI's ja path in locales.rst

Review of #984: a Parser holding ja_segmenter() cannot be pickled at
all (its segmenter is a local closure), so the declined library-wide
attach would stop parser_for(locales.JA) pickling wherever the extra is
installed, not carry a callable. The entry gains its verdict headline
and #984, the Standing line points at it, and both describe the note
that now replaces the warning. locales.rst no longer reads as if the
CLI were parser_for(locales.get(code)) for every code; usage.rst and
the release log say note, not warning.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Test the CLI's namedivider check itself

Every in-process test stands in for _ja_extra_installed, and the
subprocess runs that reach it are not measured, so its line went
uncovered (codecov/patch 94.73%). The new test calls it and holds it to
the find_spec answer the subprocess tests' skips are keyed on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant